#ifndef GENIE_CURVE
#define GENIE_CURVE

#include "common.h"

// MAXIMUM speed allowed by the PCU adjustment in SPEED_AJDUST mode.
#define SMAL_SLAB_FAST_PWM_LIMIT    100     // percent
#define SMAL_SLAB_RISED_PWM_LIMIT   75      // percent  was 55  Modify lower need value from Labview.
#define ELEC1_RISED_PWM_LIMIT       100      // percent  ET_NOTE_1 Was 35
//#define ELEC2_RISED_PWM_LIMIT       75      // percent
#define ELEC3_RISED_PWM_LIMIT       75      // percent   ET_NOTE_2 Was 35 for Boost for 0807
#define ELEC3_SLOW_PWM_LIMIT        80      // 09012011

#define NUMBER_OF_BREAK_POINTS 6    // number of break points including two end points

struct curve
{
   // abIn_Breaks[ NUMBER_OF_BREAK_POINTS - 1] must be be equal to (X_MAX - NEUTRAL_ZONE)
   // abIn_Breaks[ 0] must be a 0
   // abPWM_Breaks[ 0] must be a 0
   // abPWM_Breaks[ NUMBER_OF_BREAK_POINTS - 1] must be equal to maximum PWM value;
   // all middle points as is from GEINIE
   // abPWM_Breaks[ 0] <= abPWM_Breaks[ 1] <= abPWM_Breaks[ 2] <= ...
   // abIn_Breaks[ 0] <= abIn_Breaks[ 1] <= abIn_Breaks[ 2] <= ...
   UINT8 abIndex[ NUMBER_OF_BREAK_POINTS ]; // the 0 and 127 is not stored
   UINT8 abPwmPos[ NUMBER_OF_BREAK_POINTS ]; //  the 0 is not stored
   UINT8 bPwmPosAdjust;       //
   UINT8 abPwmNeg[ NUMBER_OF_BREAK_POINTS ]; //  the 0 is not stored
   UINT8 bPwmNegAdjust;       //
   UINT32 nAccel;  // counts per control loop cycle X resolution factor ACCEL_DECEL_FACTOR
   UINT32 nDecel;  // counts per control loop cycle X resolution factor ACCEL_DECEL_FACTOR
   //
   // resolution factor to convert nvm acceleration and deceleration.
   //
#define ACCEL_DECEL_FACTOR  1000l
};


extern struct curve drive_fast_curve;
extern struct curve drive_rised_curve;
extern struct curve lift_up_curve;
extern struct curve drive_slow_curve;
//extern struct curve steer_fast_curve;
extern struct curve steer_rised_curve;

extern UINT8  CURVE_GetPwm(INT16 nIn, struct curve * pc);
extern UINT8  CURVE_IsEnabled(struct curve * pc);
extern void   CURVE_Setup(void);

#endif
